
package com.mephi.model.profile;


import java.util.Vector;
import com.mephi.exception.NoSuchElementException;
import com.mephi.interfaces.SimpleProfile;
import com.mephi.interfaces.ProfileList;


public enum ProfileListImpl implements ProfileList
{
	/**
     * singleton instance of class ProfileListImpl
     */
    INSTANCE;
    
	@Override
	public void add(SimpleProfile profile) throws NullPointerException
	{
		if (profile == null)
			throw new NullPointerException("Profile is null!");
		profileList.add(profile);	
	}

	@Override
	public SimpleProfile getProfile(String id) throws NoSuchElementException
	{
		if (id == null)
			throw new NullPointerException("Id is null!");
		
		SimpleProfile profile = null;
		for (SimpleProfile it: profileList)
		{
			if (it.getName().equals(id))
				profile = it;
		}
		if (profile == null)
			throw new NoSuchElementException(id);
		
		return profile;
	}

	@Override
	public void remove(String id) throws NoSuchElementException
	{
		profileList.remove(getProfile(id));
	}
	
	private ProfileListImpl()
	{
		profileList = new Vector<SimpleProfile>();
	}
	
	private Vector<SimpleProfile> profileList;
}
